package StudyCode.summary.Basic.myint;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class IntArrayToString {
	public static void main(String args[]) {
		int[] ints = new int[]{1, 2, 3, 4, 5};
		StringBuffer stringBuffer = new StringBuffer();
		String separator = " "; // 分隔符
		stringBuffer.append(ints[0]);
		for (int i = 1; i < ints.length; i++) {
			stringBuffer.append(separator).append(ints[i]);
		}
		System.out.println("方法一：使用循环追加到字符串");
		System.out.println(stringBuffer.toString());

		String strNumbers = Arrays.toString(ints);
		System.out.println("方法二(Arrays.toString方法): " + strNumbers);
		strNumbers = strNumbers.replaceAll(", ", separator).replace("[", "").replace("]", "");
		System.out.println("方法二结果替换后: " + strNumbers);
	}
}
